#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int minOperations(vector<int>& nums, int x)
    {

        int n = nums.size();
        int len = -1;
        int sum1 = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            sum1 += nums[i];
        }
        int target = sum1 - x;
        if (target < 0) return -1;
        int sum2 = 0;

        for (int left = 0, right = 0; right < n; right++)
        {
            sum2 += nums[right];
            while (sum2 > target)
            {
                sum2 = sum2 - nums[left];
                left++;
            }

            if (sum2 == target)
            {
                len = max(len, right - left + 1);
            }
        }
        if (len == -1)
            return len;
        else
            return n - len;
    }
};

int main()
{
    int arry1[] = { 3,2,20,1,1,3 };
    vector<int> s;
    for (auto e : arry1)
    {
        s.push_back(e);
    }
    Solution y;

    cout << y.minOperations(s, 10) << endl;


    return 0;
}